/*
 * advancedVectorizedNet.c
 *
 *  Created on: Dec 4, 2013
 *      Author: cinus
 */

#include "net.h"
#include "vectorizednet.h"
#include "training.h"
#include "jjann.h"

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
	uint8 status;
	int32 j;
	float32 error;
	float32 output[3];

	trainingData_t trainingData;
	trainingData_t validationData;
	netdata_tp net;
	vectorizedNet_tp vnet;

	//topology_t topo;

	srand(123456);
	fprintf(stderr, "Program started\n");

	net = initNetwork("configs/advancedVectorizedNet.cfg");
	if (net == NULL) {
		fprintf(stderr, "Network creation failed, aborting\n");
		exit(EXIT_FAILURE);
	} else {
		fprintf(stderr, "Network successfully created\n");
	}
	status = loadSamples(&trainingData, "datasets/iris.training");
	if (status != EXIT_SUCCESS) {
		fprintf(stderr, "Error, aborting software\n");
		exit(status);
	} else {
		fprintf(stderr, "Training data loaded\n");
	}

	status = loadSamples(&validationData, "datasets/iris.validation");
	if (status != EXIT_SUCCESS) {
		fprintf(stderr, "Error, aborting software\n");
		exit(status);
	} else {
		fprintf(stderr, "Validation data loaded\n");
	}
	error = .0;

	vnet = convertNet(net);
	fprintf(stderr,"Net converted\n");
	error = trainUntilConvergenceV(vnet, &trainingData, &validationData, vnet->maxEpochsFromMinimum);
	fprintf(stderr,"Vectorized Error: %f\n",error);
	error = trainUntilConvergence(net,trainingData.samples, trainingData.sampleSize, validationData.samples, validationData.sampleSize, net->settings.maxEpochsFromMinimum);
	fprintf(stderr,"Std Error: %f\n",error);
	destroyNetwork(net);
	destroyNetworkV(vnet);
	freeSamples(&trainingData);
	freeSamples(&validationData);
	return 0;
}
